<?php


namespace App\Http\Controllers\admin\service;


use App\Http\Controllers\admin\model\SettingModel;
use App\Http\Controllers\admin\model\AdminModel;
use App\Http\Controllers\admin\model\AdminSnModel;
use App\Http\Controllers\admin\model\ParentSnModel;
use App\Http\Controllers\admin\model\TeacherSnModel;
use App\Http\Controllers\utils\LogUtil;
use App\Http\Controllers\utils\ToolUtil;
use Illuminate\Support\Facades\DB;

class PADService
{
    /**
     * 老师设备锁定或解锁
     * @param $param
     * @return false|string
     */
    public static function importTeacherLocking($param){
        try {
            if(!ToolUtil::checkExcelSuffix($param)){
                return ToolUtil::returnJson(302,'文件类型必须为xlsx或xls');
            }
            $phpReader = new \PHPExcel_Reader_Excel2007();
            $phpExcel = $phpReader->load($param['file']);
            $currentSheet = $phpExcel->getSheet(0);//获取第一个表单
            $allRow = $currentSheet->getHighestRow();//获取总行数
            $maxColumn = $currentSheet->getHighestColumn();//获取最大列号
            $allColumn=\PHPExcel_Cell::columnIndexFromString($maxColumn);//获取总列数
            $noSn = [];
            $success = 0;
            $error = [];
            if($param['type']==1){
                $type = 1;
                $remark = '锁定设备';
            }else{
                $type = 0;
                $remark = '解锁设备';
            }
            $snArr = [];
            DB::beginTransaction();
            for ($currentRow=2;$currentRow<=$allRow;$currentRow++){
                for ($currentColumn=0;$currentColumn<$allColumn;$currentColumn++){
                    $val = $currentSheet->getCellByColumnAndRow($currentColumn,$currentRow)->getValue();
                    $teacher = TeacherSnModel::queryWhereFirst(['a.value'=>$val]);
                    if(!$teacher){
                        $noSn[$currentRow] = $currentRow;
                        break;
                    }
                    $int = AdminSnModel::edit(['value'=>$val],['is_lock'=>$type,'update_time'=>time()]);
                    if($int){
                        $success++;
                        $snArr[$currentRow-2] = $val;
                        $param['remark'] = $remark;
                        $param['details'] = ToolUtil::handleSuccessOrError(['snValue'=>$val]);
                        LogUtil::addAdminLog($param);
                        break;
                    }else{
                        $error[$currentRow] = $currentRow;
                        break;
                    }
                }
            }
            $data['success'] = $success;
            $data['total'] = $allRow-1;
            $data['noSn'] = array_values($noSn);
            $data['error'] = array_values($error);
            if($snArr){
                DB::commit();

                $param['type'] = 2;
                $param['status'] = 1;
                $param['contentType'] = 17;
                $param['statusType'] = $remark;
                $param['batch'] = $snArr;
                $param['title'] = 'OK';
                $jPush = LogUtil::addPushLog($param);
                if(in_array(200,$jPush)){
                    return ToolUtil::returnJson(200,'成功',$data);
                }
                return ToolUtil::returnJson(200,'成功,推送失败',$data);
                
            }
            return ToolUtil::returnJson(200,'成功',$data);
        }catch (\Exception $exception){
            DB::rollBack();
            return ToolUtil::returnJson(500,'格式错误');
        }
    }

    /**
     * 获取老师PAD设备锁定信息
     * @param $param
     * @return false|string
     */
    public static function queryTeacherLocking($param){
        $admin = AdminModel::queryFirst(['id'=>$param['userId']],['group_id']);
        $field = ['as.value','a.username','b.name','as.is_lock'];
        $where['as.is_lock'] = 0;
        if($admin['group_id']==1 || $admin['group_id']==2){
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
            }
        }elseif($admin['group_id']==3){
            $where['tn.admin_id'] = $param['userId'];
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
                    break;
            }
        }else{
            return ToolUtil::returnJson(400,'没有数据');
        }
        if(count($data['data'])){
            return ToolUtil::returnJson(200,'成功',$data['data'],$data['count']);
        }
        return ToolUtil::returnJson(400,'没有数据');
    }

    /**
     * 处理获取老师设备锁定信息
     * @param array $where
     * @param $param
     * @param $field
     * @return mixed
     */
    public static function handleQueryTeacherLocking($where=[],$param,$field){
        if($where){
            $data['count'] = TeacherSnModel::queryCount($where,$param);
            $page = ToolUtil::calculationPage($param,$data['count']);
            $data['data'] = TeacherSnModel::queryAll($where,$param,$page,$field);
        }else{
            $data['count'] = TeacherSnModel::queryCount([],$param);
            $page = ToolUtil::calculationPage($param,$data['count']);
            $data['data'] = TeacherSnModel::queryAll([],$param,$page,$field);
        }
        return $data;
    }

    /**
     * 获取家长设备锁定信息
     * @param $param
     * @return false|string
     */
    public static function queryParentLocking($param){
        $admin = AdminModel::queryFirst(['id'=>$param['userId']],['group_id']);
        $field = ['as.value','a.username','as.is_lock'];
        $where['as.is_lock'] = 0;
        if($admin['group_id']==1 || $admin['group_id']==2){
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
            }
        }elseif($admin['group_id']==4){
            $where['tp.admin_id'] = $param['userId'];
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
                    break;
            }
        }else{
            return ToolUtil::returnJson(400,'没有数据');
        }
        if(count($data['data'])){
            return ToolUtil::returnJson(200,'成功',$data['data'],$data['count']);
        }
        return ToolUtil::returnJson(400,'没有数据');
    }

    /**
     * 处理获取家长设备锁定信息
     * @param array $where
     * @param $param
     * @param $field
     * @return mixed
     */
    public static function handleQueryParentLocking($where=[],$param,$field){
        if($where){
            $data['count'] = ParentSnModel::queryCount($where,$param);
            $page = ToolUtil::calculationPage($param,$data['count']);
            $data['data'] = ParentSnModel::queryAll($where,$param,$page,$field);
        }else{
            $data['count'] = ParentSnModel::queryCount([],$param);
            $page = ToolUtil::calculationPage($param,$data['count']);
            $data['data'] = ParentSnModel::queryAll([],$param,$page,$field);
        }
        return $data;
    }

    /**
     * 家长设备锁定或解锁
     * @param $param
     * @return false|string
     */
    public static function importParentLocking($param){
        try {
            if(!ToolUtil::checkExcelSuffix($param)){
                return ToolUtil::returnJson(302,'文件类型必须为xlsx或xls');
            }
            $phpReader = new \PHPExcel_Reader_Excel2007();
            $phpExcel = $phpReader->load($param['file']);
            $currentSheet = $phpExcel->getSheet(0);//获取第一个表单
            $allRow = $currentSheet->getHighestRow();//获取总行数
            $maxColumn = $currentSheet->getHighestColumn();//获取最大列号
            $allColumn=\PHPExcel_Cell::columnIndexFromString($maxColumn);//获取总列数
            $noSn = [];
            $success = 0;
            $error = [];
            if($param['type']==1){
                $type = 1;
                $remark = '锁定设备';
            }else{
                $type = 0;
                $remark = '解锁设备';
            }
            $snArr = [];
            $bindTeacher = [];
            DB::beginTransaction();
            for ($currentRow=2;$currentRow<=$allRow;$currentRow++){
                for ($currentColumn=0;$currentColumn<$allColumn;$currentColumn++){
                    $val = $currentSheet->getCellByColumnAndRow($currentColumn,$currentRow)->getValue();
                    $teacher = ParentSnModel::queryWhereFirst(['a.value'=>$val]);
                    if(!$teacher){
                        $noSn[$currentRow] = $currentRow;
                        break;
                    }
                    if($teacher['teacher_id']){
                        $bindTeacher[$currentRow] = $currentRow;
                        break;
                    }
                    $int = AdminSnModel::edit(['value'=>$val],['is_lock'=>$type,'update_time'=>time()]);
                    if($int){
                        $success++;
                        $snArr[$currentRow-2] = $val;
                        $param['remark'] = $remark;
                        $param['details'] = ToolUtil::handleSuccessOrError(['snValue'=>$val]);
                        LogUtil::addAdminLog($param);
                        break;
                    }else{
                        $error[$currentRow] = $currentRow;
                        break;
                    }
                }
            }
            $data['success'] = $success;
            $data['total'] = $allRow-1;
            $data['noSn'] = array_values($noSn);
            $data['error'] = array_values($error);
            $data['bTeacher'] = array_values($bindTeacher);
            if($snArr){
                DB::commit();
                
                $param['type'] = 2;
                $param['status'] = 1;
                $param['contentType'] = 17;
                $param['statusType'] = $remark;
                $param['batch'] = $snArr;
                $param['title'] = 'OK';
                $jPush = LogUtil::addPushLog($param);
                if(in_array(200,$jPush)){
                    return ToolUtil::returnJson(200,'成功',$data);
                }
                return ToolUtil::returnJson(200,'成功,推送失败',$data);
                
            }
            return ToolUtil::returnJson(200,'成功',$data);
        }catch (\Exception $exception){
            DB::rollBack();
            return ToolUtil::returnJson(500,'格式错误');
        }
    }

    /**
     * 老师设备重启或恢复出厂模式
     * @param $param
     * @return false|string
     * @throws \PHPExcel_Exception
     * @throws \PHPExcel_Reader_Exception
     */
    public static function importTeacherReset($param){
        if(!ToolUtil::checkExcelSuffix($param)){
            return ToolUtil::returnJson(302,'文件类型必须为xlsx或xls');
        }
        $phpReader = new \PHPExcel_Reader_Excel2007();
        $phpExcel = $phpReader->load($param['file']);
        $currentSheet = $phpExcel->getSheet(0);//获取第一个表单
        $allRow = $currentSheet->getHighestRow();//获取总行数
        $maxColumn = $currentSheet->getHighestColumn();//获取最大列号
        $allColumn=\PHPExcel_Cell::columnIndexFromString($maxColumn);//获取总列数
        $noSn = [];
        $success = 0;
        $error = [];
        $type = $param['type'];
        if($param['type']==1){
            $remark = '重启';
        }else{
            $remark = '恢复出厂设置';
        }
        $snArr = [];
        DB::beginTransaction();
        for ($currentRow=2;$currentRow<=$allRow;$currentRow++){
            for ($currentColumn=0;$currentColumn<$allColumn;$currentColumn++){
                $val = $currentSheet->getCellByColumnAndRow($currentColumn,$currentRow)->getValue();
                $teacher = TeacherSnModel::queryWhereFirst(['a.value'=>$val]);
                if(!$teacher){
                    $noSn[$currentRow] = $currentRow;
                    break;
                }
                if($param['type']==2){
                    $int = AdminSnModel::edit(['value'=>$val],['is_reset'=>1,'update_time'=>time()]);
                    if(!$int){
                        $error[$currentRow] = $currentRow;
                        break;
                    }
                }
                $success++;
                $snArr[$currentRow-2] = $val;
                $param['remark'] = $remark;
                $param['details'] = ToolUtil::handleSuccessOrError(['snValue'=>$val]);
                LogUtil::addAdminLog($param);
                break;
            }
        }
        $data['success'] = $success;
        $data['total'] = $allRow-1;
        $data['noSn'] = array_values($noSn);
        $data['error'] = array_values($error);
        if($snArr){
            DB::commit();
            $param['type'] = 2;
            $param['status'] = 1;
            $param['statusType'] = $remark;
            $param['batch'] = $snArr;
            $param['title'] = 'OK';
            if($type==1){
                $param['contentType'] = 22;
                $jPush = LogUtil::addPushLog($param);
                if(in_array(200,$jPush)){
                    return ToolUtil::returnJson(200,'成功',$data);
                }
                return ToolUtil::returnJson(200,'成功,推送失败',$data);
            }else{
                $param['contentType'] = 17;
                $jPush = LogUtil::addPushLog($param);
                if(in_array(200,$jPush)){
                    return ToolUtil::returnJson(200,'成功',$data);
                }
                return ToolUtil::returnJson(200,'成功,推送失败',$data);
            }
        }
        return ToolUtil::returnJson(200,'成功',$data);
    }

    /**
     * 获取老师远程重启和重置信息
     * @param $param
     * @return false|string
     */
    public static function queryTeacherReset($param){
        $admin = AdminModel::queryFirst(['id'=>$param['userId']],['group_id']);
        $field = ['as.value','a.username','b.name','as.is_reset'];
        $where['as.is_reset'] = 1;
        if($admin['group_id']==1 || $admin['group_id']==2){
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
            }
        }elseif($admin['group_id']==3){
            $where['tn.admin_id'] = $param['userId'];
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryTeacherLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
                    break;
            }
        }else{
            return ToolUtil::returnJson(400,'没有数据');
        }
        if(count($data['data'])){
            return ToolUtil::returnJson(200,'成功',$data['data'],$data['count']);
        }
        return ToolUtil::returnJson(400,'没有数据');
    }

    /**
     * 家长设备重启或恢复出厂模式
     * @param $param
     * @return false|string
     * @throws \PHPExcel_Exception
     * @throws \PHPExcel_Reader_Exception
     */
    public static function importParentReset($param){
        if(!ToolUtil::checkExcelSuffix($param)){
            return ToolUtil::returnJson(302,'文件类型必须为xlsx或xls');
        }
        $phpReader = new \PHPExcel_Reader_Excel2007();
        $phpExcel = $phpReader->load($param['file']);
        $currentSheet = $phpExcel->getSheet(0);//获取第一个表单
        $allRow = $currentSheet->getHighestRow();//获取总行数
        $maxColumn = $currentSheet->getHighestColumn();//获取最大列号
        $allColumn=\PHPExcel_Cell::columnIndexFromString($maxColumn);//获取总列数
        $noSn = [];
        $success = 0;
        $error = [];
        $type = $param['type'];
        if($param['type']==1){
            $remark = '重启';
        }else{
            $remark = '恢复出厂设置';
        }
        $snArr = [];
        DB::beginTransaction();
        for ($currentRow=2;$currentRow<=$allRow;$currentRow++){
            for ($currentColumn=0;$currentColumn<$allColumn;$currentColumn++){
                $val = $currentSheet->getCellByColumnAndRow($currentColumn,$currentRow)->getValue();
                $teacher = ParentSnModel::queryWhereFirst(['a.value'=>$val]);
                if(!$teacher){
                    $noSn[$currentRow] = $currentRow;
                    break;
                }
                if($param['type']==2){
                    $int = AdminSnModel::edit(['value'=>$val],['is_reset'=>1,'update_time'=>time()]);
                    if(!$int){
                        $error[$currentRow] = $currentRow;
                        break;
                    }
                }
                $success++;
                $snArr[$currentRow-2] = $val;
                $param['remark'] = $remark;
                $param['details'] = ToolUtil::handleSuccessOrError(['snValue'=>$val]);
                LogUtil::addAdminLog($param);
                break;
            }
        }
        $data['success'] = $success;
        $data['total'] = $allRow-1;
        $data['noSn'] = array_values($noSn);
        $data['error'] = array_values($error);
        if($snArr){
            DB::commit();
            $param['type'] = 2;
            $param['status'] = 1;
            $param['statusType'] = $remark;
            $param['batch'] = $snArr;
            $param['title'] = 'OK';
            if($type==1){
                $param['contentType'] = 22;
                $jPush = LogUtil::addPushLog($param);
                if(in_array(200,$jPush)){
                    return ToolUtil::returnJson(200,'成功',$data);
                }
                return ToolUtil::returnJson(200,'成功,推送失败',$data);
            }else{
                $param['contentType'] = 17;
                $jPush = LogUtil::addPushLog($param);
                if(in_array(200,$jPush)){
                    return ToolUtil::returnJson(200,'成功',$data);
                }
                return ToolUtil::returnJson(200,'成功,推送失败',$data);
            }
        }
        return ToolUtil::returnJson(200,'成功',$data);
    }

    /**
     * 获取家长远程重启和重置信息
     * @param $param
     * @return false|string
     */
    public static function queryParentReset($param){
        $admin = AdminModel::queryFirst(['id'=>$param['userId']],['group_id']);
        $field = ['as.value','a.username','as.is_reset'];
        $where['as.is_reset'] = 1;
        if($admin['group_id']==1 || $admin['group_id']==2){
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
            }
        }elseif($admin['group_id']==4){
            $where['tp.admin_id'] = $param['userId'];
            switch ($param['type']){
                case 1:
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 2:
                    $param['field'] = 'as.value';
                    $param['as.value'] = $param['snValue'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                case 3:
                    $param['field'] = 'a.username';
                    $param['a.username'] = $param['username'];
                    $data = self::handleQueryParentLocking($where,$param,$field);
                    break;
                default:
                    $data['data'] = null;
                    break;
            }
        }else{
            return ToolUtil::returnJson(400,'没有数据');
        }
        if(count($data['data'])){
            return ToolUtil::returnJson(200,'成功',$data['data'],$data['count']);
        }
        return ToolUtil::returnJson(400,'没有数据');
    }


    /**
     * 管理员解绑设备
     * @param $param
     * @return false|string
     */
    public static function adminRelieveBindSn($param){

        try {

            $admin = AdminModel::queryFirst(['id'=>$param['userId']],['sn_num','group_id']);
            if(empty($admin)){
                return ToolUtil::returnJson(300,'用户编号错误');
            }
            if(empty(ToolUtil::checkIsAdmin($admin['group_id']))){
                return ToolUtil::returnJson(300,'没有权限');
            }

            $parentSn = DB::table('t_parent_sn as p')
                ->leftJoin('t_admin_sn as a','p.admin_sn_id','=','a.id')
                ->where(['a.value'=>$param['sn']])
                ->first(['p.id','p.admin_id']);
            if(empty($parentSn)){
                return ToolUtil::returnJson(301,'没有该设备信息');
            }
            $sn_admin = AdminModel::queryFirst(['id'=>$parentSn['admin_id']],['sn_num']);
            if(empty($sn_admin)){
                return ToolUtil::returnJson(301,'设备用户错误');
            }

            DB::beginTransaction();
            
            $sn_del = ParentSnModel::delete(['id'=>$parentSn['id']]);
            $bind = DB::table('t_bind_sn')->where(['sn_value'=>$param['sn']])->delete();
            
            if($sn_admin['sn_num'] < 0){
                $snNum = 0;
            }else{
                $snNum = $sn_admin['sn_num']-1;
            }

            AdminModel::edit(['id'=>$parentSn['admin_id']],['sn_num'=>$snNum]);
            SettingModel::delete(['admin_id'=>$parentSn['admin_id'],'sn_value'=>$param['sn']]);

            DB::table('t_app_ground')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_app_inside')->where(['sn'=>$param['sn']])->delete();
            DB::table('t_app_install')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_app_jump')->where(['sn'=>$param['sn']])->delete();
            DB::table('t_app_log')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_app_use_info')->where(['sn'=>$param['sn']])->delete();
            DB::table('t_browser')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_parent_app')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_run_app')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_screenshot')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_sn_uid')->where(['sn'=>$param['sn']])->delete();
            DB::table('t_statistics_app')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_time_control')->where(['sn_value'=>$param['sn']])->delete();
            DB::table('t_white_app')->where(['sn'=>$param['sn']])->delete();

            if($sn_del>0 && $bind>0){
                $adminSn = [
                    'model'=>'',
                    'addr'=>'',
                    'imel'=>'',
                    'system'=>'',
                    'devices_version'=>'',
                    'orm_version'=>'',
                    'screen_px'=>'',
                    'quantity'=>'',
                    'device_memory'=>'',
                    'storage'=>'',
                    'cpu'=>'',
                    'name'=>'',
                    'avatar'=>'https://zuoyepad.oss-cn-beijing.aliyuncs.com/zuoyapdsetting/2.png',
                    'appstore_version'=>'',
                    'updatetools_version'=>'',
                    'info_version'=>'',
                    'jiaoguanyi_version'=>'',
                    'gankao_version'=>'',
                    'online'=>0,
                    'school'=>null,
                    'mac'=>'',
                    'is_lock'=>1,
                    'is_reset'=>0,
                    'is_wifi'=>0,
                    'start_time'=>0,
                    'end_time'=>0,
                    'minute'=>0,
                    'longitude'=>'',
                    'latitude'=>'',
                    'unbound_time'=>time(),
                    'is_screen_lock'=>0
                    ];
                AdminSnModel::edit(['value'=>$param['sn']],$adminSn);
                $param['remark'] = '管理员解除设备绑定';
                $param['details'] = ToolUtil::handleSuccessOrError(['sn'=>$param['sn']]);
                LogUtil::addAdminLog($param);
                $param['title'] = 'OK';
                $param['contentType'] = 17;
                $param['status'] = 1;
                $param['batch'] = array($param['sn']);
                $param['type'] = 2;
                $param['statusType'] = '管理员解除设备绑定';
                $jPush = LogUtil::addPushLog($param);
                DB::commit();
                if(in_array(200,$jPush)){
                    return ToolUtil::returnJson(200,'解绑成功');
                }
                return ToolUtil::returnJson(200,'解绑成功,推送失败');
            }
            return ToolUtil::returnJson(300,'失败');
            
        }catch (\Exception $exception){
            DB::rollBack();
            return ToolUtil::returnJson(500,'网络拥堵，请稍后再试');
        }        

    }


}